//
//  MovieViewController.m
//  DAMovie
//
//  Created by 宋伟青 on 2017/12/24.
//  Copyright © 2017年 宋伟青. All rights reserved.
//

#import "MovieViewController.h"
#import "VideoViewController.h"

@interface MovieViewController ()<UIWebViewDelegate>
@property (nonatomic, strong) UIWebView *webView;
@end

@implementation MovieViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
    NSURL *url = [NSURL URLWithString:@"https://www.2060v.com"];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [self.webView loadRequest:request];
    self.webView.scalesPageToFit = YES;
    self.webView.delegate = self;
    [self.view addSubview:self.webView];
    
    UIBarButtonItem *rightButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"回退" style:UIBarButtonItemStylePlain target:self action:@selector(gobackClick)];
    self.navigationItem.rightBarButtonItem = rightButtonItem;
}

- (void)gobackClick {
    if (self.webView.canGoBack) {
        [self.webView goBack];
    }
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    if ([request.URL.pathExtension isEqualToString:@"mp4"]) {
        VideoViewController *videoVC = [[VideoViewController alloc] init];
        //        videoVC.url = [NSURL URLWithString:@"http://mp4.vjshi.com/2017-06-29/026bfd7d6ecc4521edaadb5ac08a2487.mp4"];
        videoVC.url = request.URL;
        [self.navigationController pushViewController:videoVC animated:YES];
        return NO;
    }else {
        return YES;
    }
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    
}



@end
